package com.br4mmie.asciistory.battle;

import java.util.ArrayList;

import com.br4mmie.asciistory.CharImage;
import com.br4mmie.asciistory.mission.Item;


/**
 * Enemy class, represents enemies in a battle
 * @author Niels
 *
 */
public class Enemy extends EncounterCreature{
	
	private EnemyType type; //the type of Enemy
	
	private int screenPosX; //the position of the enemy in the battle screen
	private int screenPosY; 
	
	private ArrayList<ScriptedAction> actions;//the actions available to the Enemy. note that these are ScriptedActions!
	
	private int xpValue; //the amount of XP this Enemy is worth
	private int goldValue; //the amount of gold this creature drops
	/**
	 * Constructor
	 * @param t the type of this enemy
	 * @param b the battle this enemy is acting in
	 */
	Enemy(EnemyType t, Battle b)
	{
		type = t;
		name = t.getName();
		maxHP = t.getHp();
		xpValue = t.getXpValue();
		goldValue = t.getGoldValue();
		actions = t.getActions();
		currentHP = maxHP;
		myBattle = b;
		screenPosX = 1;
		screenPosY = 1;
		bonusDamage = t.getBonusDamage();
		defense = t.getDefense();	
	}
	
	/**
	 * Act function, checks which action is the most favored allowed by its script and then casts that ability
	 */
	public void act()
	{
		for (ScriptedAction a : actions)
		{
			if (a.act(myBattle, this)) return;
		}
	}
	/**
	 * getDrops, Adds this Creatures drops to the passed ItemList
	 * @param list ArrayList<Item> to contain the drops
	 * @param roll the Roll on which to check drops
	 */
	public void getDrops(ArrayList<Item> list, int roll)
	{
		type.getDrops(list, roll);
	}

	/**
	 * Draw function, draws the enemy to the the passed CharImage at its x,y location
	 * @param target
	 */
	public void OnDraw(CharImage target) 
	{
		type.getImage().draw(target, screenPosX, screenPosY);
		//drawHP(target);	
		if (screenPosY < 5)HealthBar.draw(target, screenPosX, 1, 19, this); //HPBar.draw(target, screenPosX, 1);
		else HealthBar.draw(target, screenPosX, screenPosY-3, 19, this);//HPBar.draw(target, screenPosX, screenPosY - 8);
	}

	
	public EnemyType getType() 
	{
		return type;
	}
	public void setType(EnemyType type) 
	{
		this.type = type;
	}
	public int getScreenPosX() 
	{
		return screenPosX;
	}
	public void setScreenPosX(int screenPosX) 
	{
		this.screenPosX = screenPosX;
	}
	public int getScreenPosY() 
	{
		return screenPosY;
	}
	public void setScreenPosY(int screenPosY) 
	{
		this.screenPosY = screenPosY;
	}
	public int getXpValue() 
	{
		return xpValue;
	}
	public int getGold()
	{
		return goldValue;
	}
	public void setXpValue(int xpValue) 
	{
		this.xpValue = xpValue;
	}
	public int getHeight()
	{
		return type.getImage().getHeight();
	}
	public int getWidth()
	{
		return type.getImage().getWidth();
	}
}

	
	

